// 这份代码专门处理逻辑层的操作
const powerDao = require('../dao/powerDao');

const powerService = {
    /*
     * 判断某个uid用户是否含有某个权限
     */
    async checkPowerByUid(uid, powerName) {
        // 用户权限认证
        let result;
        try {
            result = await powerDao.checkPowerByUid(uid, powerName);
            if (result.length > 0) {
                result = true;
            } else {
                result = false;
            }
        } catch (err) {
            result = false;
        }
        return result;
    },
    /*
     * 获取用户权限列表
     */
    async getUserPowerList(uid) {
        let result;
        try {
            result = await powerDao.getUserPowerList(uid);
            result = {success: true, powerList: result}
        } catch (err) {
            result = {success: false, msg: "获取权限列表失败"};
        }
        return result;
    }
};

module.exports = powerService;